package com.ruoyi.contract.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contract.domain.CollectionBill;
import com.ruoyi.contract.service.ICollectionBillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收款管理Controller
 * 
 * @author 张毅然
 * @date 2021-04-26
 */
@RestController
@RequestMapping("/contract/collection")
public class CollectionBillController extends BaseController
{
    @Autowired
    private ICollectionBillService collectionBillService;

    /**
     * 查询收款管理列表
     */
    @PreAuthorize("@ss.hasPermi('contract:collection:list')")
    @GetMapping("/list")
    public TableDataInfo list(CollectionBill collectionBill)
    {
        startPage();
        List<CollectionBill> list = collectionBillService.selectCollectionBillList(collectionBill);
        return getDataTable(list);
    }

    /**
     * 导出收款管理列表
     */
    @PreAuthorize("@ss.hasPermi('contract:collection:export')")
    @Log(title = "收款管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CollectionBill collectionBill)
    {
        List<CollectionBill> list = collectionBillService.selectCollectionBillList(collectionBill);
        ExcelUtil<CollectionBill> util = new ExcelUtil<CollectionBill>(CollectionBill.class);
        return util.exportExcel(list, "收款管理数据");
    }

    /**
     * 获取收款管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:collection:query')")
    @GetMapping(value = "/{gid}")
    public AjaxResult getInfo(@PathVariable("gid") String gid)
    {
        return AjaxResult.success(collectionBillService.selectCollectionBillById(gid));
    }

    /**
     * 新增收款管理
     */
    @PreAuthorize("@ss.hasPermi('contract:collection:add')")
    @Log(title = "收款管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CollectionBill collectionBill)
    {
        return toAjax(collectionBillService.insertCollectionBill(collectionBill));
    }

    /**
     * 修改收款管理
     */
    @PreAuthorize("@ss.hasPermi('contract:collection:edit')")
    @Log(title = "收款管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CollectionBill collectionBill)
    {
        return toAjax(collectionBillService.updateCollectionBill(collectionBill));
    }

    /**
     * 删除收款管理
     */
    @PreAuthorize("@ss.hasPermi('contract:collection:remove')")
    @Log(title = "收款管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gids}")
    public AjaxResult remove(@PathVariable String[] gids)
    {
        return toAjax(collectionBillService.deleteCollectionBillByIds(gids));
    }
    /**
     * 确认收款管理
     */
    @PreAuthorize("@ss.hasPermi('contract:collection:approve')")
    @GetMapping(value = "/approve/{gid}")
    public AjaxResult approve(@PathVariable String gid)
    {
        return toAjax(collectionBillService.approveCollectionBillById(gid));
    }
}
